package com.example.liuxing.android.activity.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.liuxing.android.R;

/**
 * Created by liuxing on 2017/6/26.
 */

public class SettingItemView extends RelativeLayout {

    private TextView tv_name;
    private ImageView iv_setting_logo;
    private RelativeLayout rv_setting_icon;

    public SettingItemView(Context context) {
        this(context, null);
    }

    public SettingItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
        initData(attrs);
    }

    private void initView() {
        View view = View.inflate(getContext(), R.layout.view_item, this);
        tv_name = (TextView)findViewById(R.id.tv_name);
        iv_setting_logo = (ImageView)findViewById(R.id.iv_setting_logo);
        rv_setting_icon = (RelativeLayout)findViewById(R.id.rv_setting_icon);
    }

    /**
     *
     * @param attrs 当前所有的属性
     */
    private void initData(AttributeSet attrs) {
        String desc = attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "decs");
        tv_name.setText(desc);

        String position = attrs.getAttributeValue("http://schemas.android.com/apk/res-auto", "position");
        switch (Integer.parseInt(position)) {
            case 0:
                rv_setting_icon.setBackgroundResource(R.drawable.iv_first_selector);
                break;
            case 1:
                rv_setting_icon.setBackgroundResource(R.drawable.iv_middle_selector);
                break;
            case 2:
                rv_setting_icon.setBackgroundResource(R.drawable.iv_last_selector);
                break;
        }
    }
}
